import { ref, reactive, toRefs, onMounted, nextTick, onActivated } from 'vue'

import { returnTask, commitAccet } from '@/apis/Task'
import { deleteAbnormal } from '@/apis/Abnormal'
import { deleteModule } from '@/apis/Module'
import { deleteFacadeFile } from '@/apis/Facade'
import { deleteAbnormalFile } from '@/apis/Abnormal'
import { Dialog, Toast } from 'qmp-component'
import { SimpleEvents } from '@/utils'

/**
 * 任务退回确认
 * @param {string} caid 验收ID
 */
export function TaskReturn(caid: string, callBack?: Function) {
  Dialog.confirm({
    message: '【退回】操作以后，当前所选验收将被退回，确定要退回吗？',
    confirmButtonColor: '#CC3535',
    confirmButtonText: '退回'
  }).then(() => {
    returnTask(caid).then((res: any) => {
      Toast('退回成功')
      // SimpleEvents.emit('refreshTaskList')
      // 退回操作成功后，列表切换到任务管理的 “4 已完成”
      SimpleEvents.emit('changeTaskListTab', '4')
      callBack && callBack()
    })
  })
}

/**
 * 验收任务提交
 * @param {string} caid 验收ID
 */
export function TaskCommit(caid: string, callBack?: Function) {
  Dialog.confirm({
    message: '确定要提交任务吗？'
  }).then(() => {
    commitAccet(caid).then((res: any) => {
      Toast('提交成功')
      // SimpleEvents.emit('refreshTaskList')
      // 提交操作成功后，返回列表时，tab切换到“3 已提交”
      SimpleEvents.emit('changeTaskListTab', '3')
      callBack && callBack()
    })
  })
}

/**
 * 异常验收删除确认
 * @param {string} said 异常ID
 * */
export function AbnormalDelete(said: string, callBack?: Function) {
  Dialog.confirm({
    message: '删除当前异常问题',
    confirmButtonColor: '#CC3535',
    confirmButtonText: '删除'
  }).then(() => {
    deleteAbnormal(said).then((res: any) => {
      Toast('删除成功')
      callBack && callBack()
    })
  })
}

/**
 * 验收模块(验收区域)删除确认
 * @param {string} amid 异常ID
 * */
export function ModuleDelete(amid: string, callBack?: Function) {
  Dialog.confirm({
    message: '删除当前所选区域',
    confirmButtonColor: '#CC3535',
    confirmButtonText: '删除'
  }).then(() => {
    deleteModule(amid).then((res: any) => {
      Toast('删除成功')
      callBack && callBack()
    })
  })
}

/**
 * 验收立面问题(验收立面)删除确认
 * @param {string} ffid 问题ID
 * */
export function FileDelete(ffid: string, callBack?: Function) {
  Dialog.confirm({
    message: '删除当前问题',
    confirmButtonColor: '#CC3535',
    confirmButtonText: '删除'
  }).then(() => {
    deleteFacadeFile(ffid).then((res: any) => {
      Toast('删除成功')
      callBack && callBack()
    })
  })
}

/**
 * 验收异常图片(验收异常)删除确认
 * @param {Array} sfids 问题ID集合
 * */
export function AbnormalFileDelete(sfids: string, callBack?: Function) {
  Dialog.confirm({
    message: '删除当前问题',
    confirmButtonColor: '#CC3535',
    confirmButtonText: '删除'
  }).then(() => {
    deleteAbnormalFile(sfids).then((res: any) => {
      Toast('删除成功')
      callBack && callBack()
    })
  })
}
